package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowedOperation implements IOPeration{

    @Override
    public void work(BookList bookList) {

        System.out.println("请输入你要借阅的书:");
        Scanner scanner = new Scanner(System.in);
        String bookName = scanner.nextLine();
        int currentSize = bookList.getUsedSize();

        for(int i = 0; i < currentSize; i++){
            Book book = bookList.getBooks(i);
            if(book.getName().equals(bookName)){
                if(book.isLend() == true){
                    System.out.println("你要借阅的书已被借阅");
                    return;
                }
                book.setLend(true);
                System.out.println("借阅成功");
                return;
            }
        }

        System.out.println("未找到你所要借阅的书，借阅失败");
    }
}
